Skip to content

fix: report NEXT VALUE FOR and s.NEXTVAL as possible data changes - #2934

Open
tanjiroK-coder wants to merge 1 commit into
JSQLParser:masterfrom
tanjiroK-coder:statementfeatures-sequence-nextval
Open

tanjiroK-coder wants to merge 1 commit into
JSQLParser:masterfrom
tanjiroK-coder:statementfeatures-sequence-nextval

Conversation

@tanjiroK-coder

Copy link
Copy Markdown
Contributor

StatementFeatureVisitor sends every Function through the pure-function check, so SELECT nextval('s') comes back with MODIFIES_DATA possible and nextval unresolved, and the read-only guard in usage.rst (if (connection.isReadOnly() && features.mayModifyData())) rejects it. The other two ways the grammar spells a sequence advance never get there: NEXT VALUE FOR s / NEXTVAL FOR s (SQL Server, H2, DB2, HSQLDB) parse to a NextValExpression, Oracle's s.NEXTVAL is kept as a Column named nextval (the @todo in Column()), and FeatureExpressionVisitor overrides neither. So SELECT NEXT VALUE FOR s, SELECT s.NEXTVAL FROM dual and the same expressions in a WHERE clause or a subquery report mayModifyData() == false with no unresolved reference and pass the guard, although each one advances the sequence just like nextval('s'), and a rollback does not undo that. I found it while comparing the function form of nextval with the other sequence syntaxes the parser accepts. Both nodes now go through analyseFunction("nextval"), so they report the same possible MODIFIES_DATA / MODIFIES_SCHEMA and unresolved nextval as the function form, and a caller's pure-function predicate treats all three alike; an unqualified nextval column and t.currval are unchanged. Six parameterized StatementFeatureVisitorTest cases fail before and pass after. spotless, checkstyle, PMD, SpotBugs, the grammar ambiguity check and the test suite pass, except for 35 Mockito and temp-dir test failures that fail the same way on master on my Windows machine.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant